// pages/comontants/start_tine/start_tine.js
const app = getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    limit: String
  },

  /**
   * 组件的初始数据
   */
  data: {
    multiArray: ["08:00","08:30","09:00","09:30","10:00","10:30","11:00","11:30","12:00","12:30","13:00","13:30","14:00","14:30","15:00","15:30","16:00","16:30","17:00","17:30","18:00","18:30","19:00","19:30","20:00","20:30","21:00","21:30","22:00","22:30","23:00"]
  },
  observers:{ //监听数据的更改
    "limit"(data){
      data === this.data.limit //这里不要写this.setData({})
      this.time(this.data.limit)
    }
  },
  ready(){
    this.timee(app.globalData.se_time.start_time)
  },
  methods: {
    bindPickerChange: function(e) {
      app.globalData.se_time.start_time=this.data.multiArray[e.detail.value]
      app.globalData.se_time.start_stamp=this.time_to_sec(this.data.multiArray[e.detail.value])
      this.setData({
        index: e.detail.value
      })
      this.triggerEvent('changeName', true)
    },
    timee:function(val){
	
      var multiArray = ["08:00","08:30","09:00","09:30","10:00","10:30","11:00","11:30","12:00","12:30","13:00","13:30","14:00","14:30","15:00","15:30","16:00","16:30","17:00","17:30","18:00","18:30","19:00","19:30","20:00","20:30","21:00","21:30","22:00","22:30","23:00"]
      for(var i=0;i<multiArray.length;i++){
        if(multiArray[i]===val){
          multiArray=multiArray.splice(i)
          app.globalData.se_time.start_stamp=this.time_to_sec(val)
          this.setData({
            multiArray:multiArray,
            index:0
          })
        }
      }
    },
    time:function(val){

      var multiArray = ["08:00","08:30","09:00","09:30","10:00","10:30","11:00","11:30","12:00","12:30","13:00","13:30","14:00","14:30","15:00","15:30","16:00","16:30","17:00","17:30","18:00","18:30","19:00","19:30","20:00","20:30","21:00","21:30","22:00","22:30"]
      for(var i=0;i<multiArray.length;i++){
        if(multiArray[i]===val){
          multiArray=multiArray.splice(i)
          app.globalData.se_time.start_stamp=this.time_to_sec(val)
          this.setData({
            multiArray:multiArray,
            index:0
          })
        }
        // else{
        //   multiArray=multiArray.splice(0)
        //   app.globalData.se_time.start_stamp=this.time_to_sec("8:00")
        //   this.setData({
        //     multiArray:multiArray,
        //     index:0
        //   })
        // }
      }
    },
    time_to_sec(time) {
      　　if (time !== null) {
      　　　　var s = "";
      　　　　var hour = time.split(":")[0];
      　　　　var min = time.split(":")[1];
      　　　　s = Number(hour * 3600) + Number(min * 60);
      　　　　return s;
      　　}
      },
  }
})
